<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>删除菜品</title>
    <style>
        div {
            position: absolute;
            top: 30%;
            left: 50%;
            transform: translate(-50%, -50%);
            text-align: center;
        }

        table, tr, th, td {
            border: 1px solid #5fbdcb;
        }

        table {
            border-collapse: collapse;
        }
    </style>
</head>
<body>
<div>
    <input type="button" id="button" value="确定删除吗？">
    <a id="a">返回</a>
</div>
<script src="https://lib.sinaapp.com/js/jquery/2.0.2/jquery-2.0.2.min.js"></script>
<script>
    function getParam(url, name) {
        try {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = url.split('?')[1].match(reg);
            if (r != null) {
                return r[2];
            }
            return "";
        } catch (e) {
            return "";
        }
    }

    let url = window.location.href;
    let storeId = getParam(url, 'storeId');
    let dishId = getParam(url, 'dishId');
    $(function () {
        let a = document.querySelector("#a");
        a.href = 'SellerDishPage.jsp?storeId=' + storeId;
        $(':button').on('click', function () {
            $.ajax({
                url: "http://localhost:8080/dish.do",
                type: "post",
                data: {
                    storeId: storeId,
                    dishId: dishId,
                    method: 'deleteDish'
                },
                dataType: "text",
                success: function (data) {
                    if (data === 'ok') {
                        alert("删除成功");
                        window.location.href = 'SellerDishPage.jsp?storeId=' + storeId;
                    } else {
                        alert("删除失败");
                    }
                }
            })
        })
    })
</script>
</body>
</html>
